package br.inf.solutions.apresentacoes.ssp.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import br.com.vexillum.model.annotations.Validate;
import br.com.vexillum.model.annotations.ValidatorClass;
import br.inf.solutions.apresentacoes.ssp.model.basics.BasicCommon;

@Entity
@SuppressWarnings("serial")
@ValidatorClass(validatorClass="br.inf.solutions.apresentacoes.ssp.control.validator.SquareValidator")
public class Square extends BasicCommon {
 
	@Column(nullable=false)
	@Validate(notNull=true)
	private String acronym;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "square",targetEntity=SquarePostGraduation.class, orphanRemoval=true)
	@Cascade(value = {CascadeType.MERGE})
	private List<SquarePostGraduation> squarePostAssociations;

	public String getAcronym() {
		return acronym;
	}

	public void setAcronym(String acronym) {
		if (acronym != null)
		{
			acronym = acronym.toUpperCase();
		}
		this.acronym = acronym;
	}

	public List<SquarePostGraduation> getSquarePostAssociations() {
		return squarePostAssociations;
	}

	public void setSquarePostAssociations(
			List<SquarePostGraduation> squarePostAssociations) {
		this.squarePostAssociations = squarePostAssociations;
	}
	
	@Override
	public String toString() {
		return getName();
	}
	
	@Override
	public boolean equals(Object obj) {
		return super.equals(obj);
	}
	 
}
 
